package models

import (
	"github.com/jinzhu/gorm"
	"kop/modules/world_boss/entity"
	"kop/util/date"
	"time"
)

func GetPoints(dB *gorm.DB, roleID, serverID int32) (*entity.BossPoints, error) {

	var data = &entity.BossPoints{
		RoleID:   roleID,
		ServerID: serverID,
	}

	if err := dB.FirstOrCreate(data).Error; err == nil {

		if data.Date != date.Date(time.Now()) {
			data.Date = date.Date(time.Now())
			data.IDsMap = make(map[int32]int32)
		}

		return data, nil

	} else {

		return nil, err
	}
}

func SavePoints(dB *gorm.DB, Points *entity.BossPoints) error {

	return dB.Save(Points).Error
}
